c++``怎样分行`显示```

来源:百度知道 编辑:UC知道 时间:2024/06/02 15:03:04
例如``#include<iostream.h>
int main()
{int x=0;
while(x<16){cout<<"HI";x=x+1;}
return 0;}
怎样令输出的16个HI分为四行四列显示````

用 endl
或 '\n':

#include<iostream.h>
int main()
{int x=0;
while(x<16){cout<<"HI"<<endl;x=x+1;}
return 0;}

#include<iostream.h>
int main()
{int x=0;
while(x<16){cout<<"HI\n";x=x+1;}
return 0;}

for (x = 0; x < 16; ++x)
{
cout << "HI";
if ( (x+1)%4 == 0 ) cout << endl;
}